package cn.com.fuhuitong.main.cate.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import cn.com.fuhuitong.base.BaseViewModel
import cn.com.fuhuitong.http.HttpResponse
import cn.com.fuhuitong.http.ViewModelSubscribeListener
import cn.com.fuhuitong.main.cate.entity.CateChildResponse
import cn.com.fuhuitong.main.cate.entity.CateGroupResponse
import cn.com.fuhuitong.main.cate.mode.CategoryManager
import io.reactivex.disposables.Disposable

class CategoryViewModel(application: Application) : BaseViewModel(application) {

    private val categoryManager: CategoryManager = CategoryManager()

    val cateGroupDataLiveData = MutableLiveData<HttpResponse<CateGroupResponse>>()

    val cateChildDataLiveData = MutableLiveData<HttpResponse<CateChildResponse>>()

    /**
     * 一级分类数据
     */
    fun cateGroup() {
        val listener =
            object : ViewModelSubscribeListener<CateGroupResponse>(cateGroupDataLiveData) {}
        val cateGroupDisposable: Disposable = categoryManager.cateGroup(listener)
        dispose.add(cateGroupDisposable)
    }

    /**
     * 二级分类数据
     */
    fun cateChild(id: Int) {
        val listener =
            object : ViewModelSubscribeListener<CateChildResponse>(cateChildDataLiveData) {}
        val cateChildDisposable: Disposable = categoryManager.cateChild(id, listener)
        dispose.add(cateChildDisposable)
    }

}